package top.fongs.spring_security_jwt.service.impl.users.user_detail;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import top.fongs.spring_security_jwt.domain.entity.users.user_detail.UserDetail;
import top.fongs.spring_security_jwt.service.inter.users.user_detail.UserDetailService;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class UserDetailServiceImpl implements UserDetailService {


    @Override
    public UserDetails loadUserByUsername( String s ) throws UsernameNotFoundException {
        return new UserDetail(
                10086L, 1, "libai", "ad942938834a3657d8dcf5279d749b8f",
                "LIBAI", "12345678912", 0, 0,
                1, mapToGrantedAuthorities( Collections.singletonList( "ROLE_ADMIN" ) )
        );
    }

    private static List< GrantedAuthority > mapToGrantedAuthorities( List< String > authorities ) {
        return authorities.stream( )
                .map( SimpleGrantedAuthority::new )
                .collect( Collectors.toList( ) );
    }
}
